#light

namespace loot

open System
open System.Windows
open System.Windows.Controls
open System.Windows.Input
open System.Windows.Media 
open Database 
    
type MainWindow = class
    inherit Window
    
    new () as this = {} then    
        
        let mainpanel = new StackPanel()
        
        // Transactions ListView
        let transactionview = new ListView()
        transactionview.Height <- 400.0
        let transactiongridview = new GridView()
        
        let gridviewcolumn0 = new GridViewColumn()
        gridviewcolumn0.Header <- "Date"        
        gridviewcolumn0.Width <- 100.0
        transactiongridview.Columns.Add(gridviewcolumn0)        
        
        let gridviewcolumn1 = new GridViewColumn()
        gridviewcolumn1.Header <- "Num"        
        gridviewcolumn1.Width <- 70.0
        transactiongridview.Columns.Add(gridviewcolumn1)        
        
        let gridviewcolumn2 = new GridViewColumn()
        gridviewcolumn2.Header <- "Description"        
        gridviewcolumn2.Width <- 150.0
        transactiongridview.Columns.Add(gridviewcolumn2)        
        
        let gridviewcolumn3 = new GridViewColumn()
        gridviewcolumn3.Header <- "Category"        
        gridviewcolumn3.Width <- 100.0
        transactiongridview.Columns.Add(gridviewcolumn3)        
        
        let gridviewcolumn4 = new GridViewColumn()
        gridviewcolumn4.Header <- "Debit"        
        gridviewcolumn4.Width <- 100.0
        transactiongridview.Columns.Add(gridviewcolumn4)        
        
        let gridviewcolumn5 = new GridViewColumn()
        gridviewcolumn5.Header <- "Credit"        
        gridviewcolumn5.Width <- 100.0
        transactiongridview.Columns.Add(gridviewcolumn5)        
        
        transactionview.View <- transactiongridview
        mainpanel.Children.Add(transactionview)
        |> ignore
        
        // Transaction fields grid
        let textboxgrid = new Grid()
        
        let gridcolumn1 = new ColumnDefinition()
        let gridcolumn2 = new ColumnDefinition()
        let gridcolumn3 = new ColumnDefinition()
        let gridcolumn4 = new ColumnDefinition()
        let gridcolumn5 = new ColumnDefinition()
        let gridcolumn6 = new ColumnDefinition()
        textboxgrid.ColumnDefinitions.Add(gridcolumn1)
        textboxgrid.ColumnDefinitions.Add(gridcolumn2)
        textboxgrid.ColumnDefinitions.Add(gridcolumn3)
        textboxgrid.ColumnDefinitions.Add(gridcolumn4)
        textboxgrid.ColumnDefinitions.Add(gridcolumn5)
        textboxgrid.ColumnDefinitions.Add(gridcolumn6)
        
        let gridrow1 = new RowDefinition()
        let gridrow2 = new RowDefinition()
        textboxgrid.RowDefinitions.Add(gridrow1)
        textboxgrid.RowDefinitions.Add(gridrow2)
        
        // Date
        let datetextblock = new TextBlock()
        datetextblock.Text <- "Date:"
        Grid.SetColumn(datetextblock, 0)
        Grid.SetRow(datetextblock, 0)
        textboxgrid.Children.Add(datetextblock)   
        |> ignore
        
        let datetextbox = new TextBox()
        datetextbox.Text <- ""   
        datetextbox.Width <- 100.0
        datetextbox.HorizontalAlignment <- HorizontalAlignment.Left
        Grid.SetColumn(datetextbox, 0)
        Grid.SetRow(datetextbox, 1)
        textboxgrid.Children.Add(datetextbox)        
        |> ignore
        
        // Num       
        let numtextblock = new TextBlock()
        numtextblock.Text <- "Num:"
        Grid.SetColumn(numtextblock, 1)
        Grid.SetRow(numtextblock, 0)
        textboxgrid.Children.Add(numtextblock)  
        |> ignore

        let numtextbox = new TextBox()
        numtextbox.Text <- ""
        numtextbox.Width <- 70.0
        numtextbox.HorizontalAlignment <- HorizontalAlignment.Left
        Grid.SetColumn(numtextbox, 1)
        Grid.SetRow(numtextbox, 1)
        textboxgrid.Children.Add(numtextbox)
        |> ignore

        // Description       
        let descriptiontextblock = new TextBlock()
        descriptiontextblock.Text <- "Description:"
        Grid.SetColumn(descriptiontextblock, 2)
        Grid.SetRow(descriptiontextblock, 0)
        textboxgrid.Children.Add(descriptiontextblock) 
        |> ignore

        let descriptiontextbox = new TextBox()
        descriptiontextbox.Text <- ""
        descriptiontextbox.Width <- 150.0
        descriptiontextbox.HorizontalAlignment <- HorizontalAlignment.Left
        Grid.SetColumn(descriptiontextbox, 2)
        Grid.SetRow(descriptiontextbox, 1)
        textboxgrid.Children.Add(descriptiontextbox)       
        |> ignore

        // Category       
        let categorytextblock = new TextBlock()
        categorytextblock.Text <- "Category:"
        Grid.SetColumn(categorytextblock, 3)
        Grid.SetRow(categorytextblock, 0)
        textboxgrid.Children.Add(categorytextblock) 
        |> ignore

        let categorycombobox = new ComboBox()        
        categorycombobox.Width <- 150.0
        categorycombobox.HorizontalAlignment <- HorizontalAlignment.Left
        Grid.SetColumn(categorycombobox, 3)
        Grid.SetRow(categorycombobox, 1)
        textboxgrid.Children.Add(categorycombobox)       
        |> ignore

        // Debit       
        let debittextblock = new TextBlock()
        debittextblock.Text <- "Debit:"
        Grid.SetColumn(debittextblock, 4)
        Grid.SetRow(debittextblock, 0)
        textboxgrid.Children.Add(debittextblock) 
        |> ignore

        let debittextbox = new TextBox()
        debittextbox.Text <- ""
        debittextbox.Width <- 100.0
        debittextbox.HorizontalAlignment <- HorizontalAlignment.Left
        Grid.SetColumn(debittextbox, 4)
        Grid.SetRow(debittextbox, 1)
        textboxgrid.Children.Add(debittextbox)               
        |> ignore

        // Credit       
        let credittextblock = new TextBlock()
        credittextblock.Text <- "Credit:"
        Grid.SetColumn(credittextblock, 5)
        Grid.SetRow(credittextblock, 0)
        textboxgrid.Children.Add(credittextblock) 
        |> ignore

        let credittextbox = new TextBox()
        credittextbox.Text <- ""
        credittextbox.Width <- 100.0
        credittextbox.HorizontalAlignment <- HorizontalAlignment.Left
        Grid.SetColumn(credittextbox, 5)
        Grid.SetRow(credittextbox, 1)
        textboxgrid.Children.Add(credittextbox)
        |> ignore

        mainpanel.Children.Add(textboxgrid)
        |> ignore
                
        // Buttons
        let buttonstackpanel = new StackPanel()
        buttonstackpanel.Orientation <- Orientation.Horizontal
        buttonstackpanel.HorizontalAlignment <- HorizontalAlignment.Center
        
        let savebutton = new Button(Content="_Save")
        buttonstackpanel.Children.Add(savebutton)        
        |> ignore
        savebutton.Click.Add
            (fun _ -> descriptiontextbox.Text <- insertAccount )
        
        let cancelbutton = new Button(Content="_Cancel")
        buttonstackpanel.Children.Add(cancelbutton)        
        |> ignore
        cancelbutton.Click.Add
            (fun _ -> MessageBox.Show("Cancelled",
                                   this.Title) |>ignore)

        mainpanel.Children.Add(buttonstackpanel)
        |> ignore
        this.Title <- "loot.NET"
        this.Content <- mainpanel
end


